O = Digital Output
T = Control functions
The OT30PidReg function implements a generic PID regulator. In addition to providing the regulation value, the function allows to suspend the regulator's update while maintaining the values of the various control registers and the same control output. In addition, you can adjust the control so that the control output is handled in inverse proportion to the error.
OT30PidReg ( aswParReg , aswParUsr, gwSetPoint, gwMeasure, aglOutReg )
Parameters:
| IN/OUT | VARIABLE TYPE | EXAMPLE NAME | DIM | |
|---|---|---|---|---|
| IN | ARRSYS | aswParReg [1] | W | Sample time PID regulator (sec/100) [0÷32767]. |
| IN | ARRSYS | aswParReg [2] | W | Maximum scale limit of regulation variable (UM) [-32768÷32767] |
| IN | ARRSYS | aswParReg [3] | W | Minimum scale limit of regulation variable (UM) [-32768÷32767] |
| IN | ARRSYS | aswParReg [4] | W | Maximum value of regulation output [-32768 ÷32767] |
| IN | ARRSYS | aswParReg [5] | W | Minimum value of regulation output [-32768 ÷32767] |
| IN | ARRSYS | aswParReg [6] | W | Positive saturation value regulation output [-32768 ÷32767] |
| IN | ARRSYS | aswParReg [7] | W | Negative saturation value regulation output [-32768 ÷32767] |
| IN | ARRSYS | aswParReg [8] | W | Setting flags: bit 0: EnableReg. Enables regulator; with disabled regulator everything is 0. bit 1: FreezeReg. Freeze updating the controller. bit 2: InvertOut. Reverses the regulator output bit 3: DisIntTm Disable the internal timer, This function should be called every sampling time. |
| IN | ARRSYS | aswParUsr [1] | W | Proportional gain.(‰)[0÷9999] |
| IN | ARRSYS | aswParUsr [2] | W | Integral time (sec/100) [0÷9999] |
| IN | ARRSYS | aswParUsr [3] | W | Derivative time (sec/100) [0÷9999] |
| IN | ARRSYS | aswParUsr [4] | W | Sample time of the derivative [0÷255] 0=sample time PID regulator 1=2*sample time PID regulator … … n=(n+1)*sample time PID regulator |
| IN | ARRSYS | aswParUsr [5] | W | Derived filter time constant (sec/100) [0÷9999] |
| IN | ARRSYS | aswParUsr [6] | W | Feed Forward (‰) [0÷2000] |
| IN | GLOBAL | gwSetPoint | W | Setpoint of regulation (UM) |
| IN | GLOBAL | gwMeasure | W | Value of the process variable(UM) |
| OUT | ARRGBL | aglOutReg[1] | L | PID output log |
| OUT | ARRGBL | aglOutReg[2] | L | Proportional output log |
| OUT | ARRGBL | aglOutReg[3] | L | Integral output log |
| OUT | ARRGBL | aglOutReg[4] | L | Derivative output log |
| OUT | ARRGBL | aglOutReg[5] | L | Feedforward output log |
| OUT | ARRGBL | aglOutReg[6] | L | Error log |
| OUT | ARRGBL | aglOutReg[7] | L | Regulator states: bit 2 = positive saturation state bit 3 = negative saturation state bit 4 = executing state regulation |
| OUT | ARRGBL | aglOutReg[8] | L | Error code |
After calling the function, the “Error code” variable in aglOutReg[8] takes certain values, the meaning of these values is summarized below:
0: No error
1: Error setting sampling time
2: Error setting lower limit and/or greater of scale
3: Error setting value proportional gain
4: Error setting integration time
5: Error setting derivative time
6: Error setting value percentage feed-forward
7: Error setting minimum and/or maximum value regulator output
8: Error setting sampling time derivative
9: Error setting derived filter time constant
10: positive saturation value setting exceeds maximum output regulator
11: negative saturation value setting exceeds maximum output regulator
;---------------------------------------------
; Example
;---------------------------------------------
aswParReg [1]=500 ; sample time = 500ms
aswParReg [2]=10000 ; full scale top = 10000
aswParReg [3]=0 ; full scale less = 0
aswParReg [4]=5000 ; Maximum output regulator value
aswParReg [5]=0 ; Minimum output regulator value
aswParReg [6]=2000 ; Positive saturation value regulator output
aswParReg [7]=0 ; Negative saturation value regulator output
aswParUsr[1] = 100 ; Proportional gain = 0.1
aswParUsr[2] = 200 ; Integral time = 2 sec.
aswParReg [8]= aswParReg [8] ORB 1 ; Enable regulation
MAIN:
gwSetPoint = 800
OT30PidReg ( aswParReg , aswParUsr, gwSetPoint, gwMeasure, aslOutReg )
WAIT 1
JUMP MAIN
A regulator reads an input variable (gwMeasure), compares it to a reference signal (gwSetPoint) and change the value of the output (aslOutReg[7]) to achieve equality of the variable with the reference.
One of the most popular types of regulators is the PID (Proportional, Integral, Derivative).
This control action establishes a relationship of direct proportionality between the error (aglOutReg[6]) and the controller output value. The proportional gain parameter (aswParUsr [1]) defines the extent of proportional action; it's expressed in thousandths, then to set gain of 0.5 you should enter the value 500.
The rule establishing the output value (aslOutReg[7]) defines: with unity gain (1000), the control output will be maximum when the error is equal to the difference between “Maximum scale limit” and “Maximum scale limit” that is the result between aswParReg [2] - aswParReg [3].
L'azione integrale del regolatore PID calcola l'integrale dell'errore su un intervallo di tempo impostabile dall'utente tramite il parametro aswParUsr [2] (espresso in centesimi di secondo). Il segnale di uscita viene aggiornato in modo particolare: ogni volta che l'integratore da un valore in uscita questo è sommato al valore che si trova sul registro, quindi esso continuerà ad incrementarsi o decrementarsi (a seconda del segno dell'errore). Il valore d'uscita è calcolato così: con guadagno proporzionale unitario, il tempo di integrazione (aswParUsr [2]) è il tempo necessario affinché lil registro integrale (aglOutReg[3]) raggiunga il valore del registro proporzionale (aglOutReg[2]). Da quest'ultima affermazione si deduce che l'azione integrale è legata all'azione proporzionale.
L'azione derivativa cerca in un certo senso di “anticipare” il comportamento del sistema che si sta controllando. L'uscita prodotta è proporzionale alla variazione del segnale di ingresso. L'entità dell'effetto derivativo è impostabile tramite il parametro tempo derivativo (aswParUsr [3]). Il calcolo dell'azione derivativa si basa sulla seguente convenzione: il tempo derivativo è il tempo necessario affinché, con variazione di errore costante, il registro derivativo (aglOutReg[4]) raggiunga un valore pari al registro proporzionale (aglOutReg[2]). Come per l'azione integrale si evince che anche per l'azione derivativa c'è un legame con l'azione proporzionale. Più alto è il tempo di derivazione dell'errore e più veloce è il sistema nel recupero dell'errore nei transitori. E' evidente comunque che l'azione derivativa non può mai essere utilizzata da sola perché in presenza di errori costanti il suo effetto sarebbe nullo.
In aggiunta al regolatore PID è presente anche l'azione feed-forward: essa genera un'uscita proporzionale al valore di setpoint (come si può dedurre dal nome non sfrutta alcuna retroazione dell'errore). La sua funzione è di ridurre il tempo di risposta del sistema fornendo un'uscita già vicina a quella che il regolatore dovrebbe raggiungere. Il contributo di questa azione è regolabile mediante il parametro feed forward (aswParUsr [6]): questo parametro è espresso come porzione millesimale (quindi per introdurre, ad esempio, 98.5% è necessario impostare il valore 985).
Impostando un valore di 100%, quando il setpoint (gwSetPoint ) sarà pari al “Limite massimo di scala” (aswParReg [2]) il valore dell'uscita feed-forward sarà pari al “valore massimo uscita di regolazione” (aswParReg [4]); quando il setpoint (gwSetPoint ) sarà pari al “Limite minimo di scala” (aswParReg [3]) il valore dell'uscita feed-forward sarà pari al “valore minimo uscita di regolazione” (aswParReg [5]);